package com.bolang.onlycode.demo.socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

/**
 * @Auther: bl_xueld
 * @Date: 2021/12/14 16:41
 * @Description:
 */
public class MyServerSocket {
    public static void main(String[] args) {
        ServerSocket serverSocket= null;
        try {
            serverSocket = new ServerSocket(8081);
            Socket socket=null;
            //记录客户端的数量
            int count=0;
            System.out.println("服务器即将启动，等待客户端连接");
            while(true){
                socket=serverSocket.accept();
                count++;
                System.out.println("建立了socket实例时间："+new Date()+"，当前客户端的数量："+count+"，当前的socket："+socket.hashCode());
            }

//

        } catch (IOException e) {
            e.printStackTrace();
        }
//

    }
}
